package com.finalterm.order.task;

import com.finalterm.order.service.CompensationTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 补偿任务处理器
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class CompensationTaskProcessor {
    
    private final CompensationTaskService compensationTaskService;
    
    /**
     * 每5分钟执行一次补偿任务处理
     */
    @Scheduled(cron = "0 */5 * * * ?")
    public void processCompensationTasks() {
        log.debug("开始处理补偿任务");
        try {
            compensationTaskService.processPendingTasks();
            log.debug("补偿任务处理完成");
        } catch (Exception e) {
            log.error("补偿任务处理失败：{}", e.getMessage(), e);
        }
    }
}
